package value

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object mapPartition {
  def main(args: Array[String]): Unit = {
    //1.创建SparkConf并设置App名称
    val conf = new SparkConf().setAppName("SparkCoreTest").setMaster("local[*]")

    //2.创建SparkContext，该对象是提交Spark App的入口
    val sc = new SparkContext(conf)

    val Rdd: RDD[Int] = sc.makeRDD(Array(3,2,6,1),2)

    val mappartitionsRdd: RDD[Int] = Rdd.mapPartitions(x => x.map(_*2))

    mappartitionsRdd.collect().foreach(println)

    //关闭
    sc.stop();
  }

}
